package com.jerry.constellation.Adapter;

import android.content.Context;
import android.graphics.Bitmap;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.jerry.constellation.R;
import com.jerry.constellation.Utils.AssetsUtils;
import com.jerry.constellation.bean.StarInfoBean;

import java.util.List;
import java.util.Map;

import de.hdodenhof.circleimageview.CircleImageView;

public class LuckyBaseAdapter extends BaseAdapter {
    private Context mcontext;
    private List<StarInfoBean.StarinfoBean> mData;
    private final Map<String, Bitmap> logoImgMap;

    public LuckyBaseAdapter(Context context, List<StarInfoBean.StarinfoBean> Data) {
        this.mcontext = context;
        this.mData = Data;
        logoImgMap = AssetsUtils.getContentlogimgMap();
    }

    @Override
    public int getCount() {
        return mData.size();
    }

    @Override
    public Object getItem(int i) {
        return mData.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder viewHolder = null;
        if (view == null) {
            view = LayoutInflater.from(mcontext).inflate(R.layout.lucky_gridview_item, null);
            viewHolder = new ViewHolder(view);
            view.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) view.getTag();
        }
        //获取指定位置所对应的数据
        StarInfoBean.StarinfoBean bean = mData.get(i);
        viewHolder.Starname.setText(bean.getName());
        Bitmap bitmap = logoImgMap.get(bean.getLogoname());
        viewHolder.StarIv.setImageBitmap(bitmap);
        return view;
    }

    class ViewHolder {
        CircleImageView StarIv;
        TextView Starname;

        public ViewHolder(View view) {
            StarIv = view.findViewById(R.id.lucky_Gv_item_icon);
            Starname = view.findViewById(R.id.lucky_Gv_item_Tv);

        }
    }
}
